package com.zhj.leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 力扣933 队列计数器
 * @author zhj
 */
public class Test933 {
    public static void main(String[] args) {
        RecentCounter rc = new RecentCounter();
        System.out.println(rc.ping(1));
        System.out.println(rc.ping(100));
        System.out.println(rc.ping(3001));
        System.out.println(rc.ping(3002));
    }
}
class RecentCounter {
    private Queue<Integer> queue;

    public RecentCounter() {
        queue = new LinkedList<>();
    }

    int ping(int t) {
        queue.add(t);
        // 计算符合3000毫秒以上出队列
        while (!queue.isEmpty() && t - queue.peek() > 3000) {
            queue.poll();
        }
        return queue.size();
    }
}